package com.irdstudio.bsp.console.service.impl;

import java.util.List;
import java.util.Objects;

import com.irdstudio.bsp.console.dao.BpmLinkedInfoDao;
import com.irdstudio.bsp.console.dao.domain.BpmLinkedInfo;
import com.irdstudio.bsp.console.service.facade.BpmLinkedInfoService;
import com.irdstudio.bsp.console.service.vo.BpmLinkedInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.sdk.beans.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 流程链接信息				<p>
 * @author srvadmin
 * @date 2020-07-24
 */
@Service("bpmLinkedInfoServiceImpl")
public class BpmLinkedInfoServiceImpl implements BpmLinkedInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(BpmLinkedInfoServiceImpl.class);

	@Autowired
	private BpmLinkedInfoDao bpmLinkedInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertBpmLinkedInfo(BpmLinkedInfoVO inBpmLinkedInfoVo) {
		logger.debug("当前新增数据为:"+ inBpmLinkedInfoVo.toString());
		int num = 0;
		try {
			BpmLinkedInfo bpmLinkedInfo = new BpmLinkedInfo();
			beanCopy(inBpmLinkedInfoVo, bpmLinkedInfo);
			num = bpmLinkedInfoDao.insertBpmLinkedInfo(bpmLinkedInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BpmLinkedInfoVO inBpmLinkedInfoVo) {
		logger.debug("当前删除数据条件为:"+ inBpmLinkedInfoVo);
		int num = 0;
		try {
			BpmLinkedInfo bpmLinkedInfo = new BpmLinkedInfo();
			beanCopy(inBpmLinkedInfoVo, bpmLinkedInfo);
			num = bpmLinkedInfoDao.deleteByPk(bpmLinkedInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBpmLinkedInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(BpmLinkedInfoVO inBpmLinkedInfoVo) {
		logger.debug("当前修改数据为:"+ inBpmLinkedInfoVo.toString());
		int num = 0;
		try {
			BpmLinkedInfo bpmLinkedInfo = new BpmLinkedInfo();
			beanCopy(inBpmLinkedInfoVo, bpmLinkedInfo);
			num = bpmLinkedInfoDao.updateByPk(bpmLinkedInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBpmLinkedInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public BpmLinkedInfoVO queryByPk(BpmLinkedInfoVO inBpmLinkedInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inBpmLinkedInfoVo);
		try {
			BpmLinkedInfo queryBpmLinkedInfo = new BpmLinkedInfo();
			beanCopy(inBpmLinkedInfoVo, queryBpmLinkedInfo);
			BpmLinkedInfo queryRslBpmLinkedInfo = bpmLinkedInfoDao.queryByPk(queryBpmLinkedInfo);
			if (Objects.nonNull(queryRslBpmLinkedInfo)) {
				BpmLinkedInfoVO outBpmLinkedInfoVo = beanCopy(queryRslBpmLinkedInfo, new BpmLinkedInfoVO());
				logger.debug("当前查询结果为:"+ outBpmLinkedInfoVo.toString());
				return outBpmLinkedInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BpmLinkedInfoVO> queryAllOwner(BpmLinkedInfoVO bpmLinkedInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BpmLinkedInfoVO> list = null;
		try {
			List<BpmLinkedInfo> bpmLinkedInfos = bpmLinkedInfoDao.queryAllOwnerByPage(bpmLinkedInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ bpmLinkedInfos.size());
			pageSet(bpmLinkedInfos, bpmLinkedInfoVo);
			list = (List<BpmLinkedInfoVO>) beansCopy(bpmLinkedInfos, BpmLinkedInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BpmLinkedInfoVO> queryAllCurrOrg(BpmLinkedInfoVO bpmLinkedInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BpmLinkedInfo> bpmLinkedInfos = bpmLinkedInfoDao.queryAllCurrOrgByPage(bpmLinkedInfoVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+bpmLinkedInfos.size());
		List<BpmLinkedInfoVO> list = null;
		try {
			pageSet(bpmLinkedInfos, bpmLinkedInfoVo);
			list = (List<BpmLinkedInfoVO>) beansCopy(bpmLinkedInfos, BpmLinkedInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BpmLinkedInfoVO> queryAllCurrDownOrg(BpmLinkedInfoVO bpmLinkedInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BpmLinkedInfo> bpmLinkedInfos = bpmLinkedInfoDao.queryAllCurrDownOrgByPage(bpmLinkedInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ bpmLinkedInfos.size());
		List<BpmLinkedInfoVO> list = null;
		try {
			pageSet(bpmLinkedInfos, bpmLinkedInfoVo);
			list = (List<BpmLinkedInfoVO>) beansCopy(bpmLinkedInfos, BpmLinkedInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
